<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/WEB-INF/layouts/include/taglib.jsp" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="decorator" content="default" />

 <script type="text/javascript">
    var prjId =  "${param.prjId}"; 	//项目id
    var prjType = "${param.prjType}"; //项目类型
    var stepId = "${param.stepId}";  //阶段id
    var taskId = "${param.taskId}";  //任务id
    var taskType = "${param.taskType}"; //选中的任务类型
    var tpId = "${param.tpId}";//模板id
    	
 </script>
</head>

<body>
<!-- 添加文档 -->
<div class="row" id="addMaster">
	<div class="col-sm-11">
		<div class="row">
			<div class="col-xs-12">
				<div class="widget-box">
					<div class="widget-header widget-header-small">
						<h5 class="smaller">新建文档<span id="" style="color:green"></span></h5>
					</div>
					<div class="widget-body">
						<div class="widget-main">
							<div class="form-group">
								<div class="col-md-6">
									<label for="empNo" class="control-label input-sm col-md-3">文档名字</label>
									<div class="col-md-7">
										<input type="text" class="form-control input-sm"
											id="tpName" name="tpName">
									</div>
								</div>
								<button class="btn btn-xs btn-success" id="addTp">
									添加文档
								</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 显示章节 -->
<div class="row" id="selectItem">
	<div class="col-sm-11">
		<div class="row">
			<div class="row col-md-12">
				<div class="col-md-6">
					<div class="widget-box">
						<div class="widget-header header-color-blue2">
							<h4 class="lighter smaller">文档章节</h4>
						</div>
		
						<div class="widget-body">
							<div class="widget-main padding-8">
								<div id="buttons">
									<button class="btn btn-success btn-sm"><i class="icon-plus-sign"></i>新增</button>
									<button class="btn btn-danger btn-sm"><i class="icon-remove"></i>删除</button>
								</div>
								<div class="hr hr-18 dotted hr-double"></div>
								<div id="menuTree" class="ztree"></div>
							</div>
							
						</div>
					</div>
				</div>
				<!-- 选择章节 -->
				<div class="col-md-6" id="saveSelectItem">
					<div class="widget-box">
						<div class="widget-header header-color-blue2">
							<h4 class="lighter smaller">章节选择</h4>
						</div>
		
						<div class="widget-body">
							<div class="widget-main padding-8 center">
								
								<span id="itemName"></span>
							</div>
							
							<div class="form-actions center" id="selectItembutton">
								<button class="btn btn-sm btn-success" type="button">
									选择章节
								</button>
								<button class="btn btn-sm btn-success" type="button">
									删除章节
								</button>
							</div>
						</div>
					</div>
				</div>
				<!-- 新增章节 -->
				<div class="col-md-6" id="addItem">						
						<div class="widget-box">
							<div class="widget-header">
								<h4 id="itemUpdate">新增章节</h4>
							</div>
							<div class="widget-body">
								<div class="widget-main no-padding">
									<form class="form-horizontal" role="form" id="menuEditForm" method="post">
										<fieldset>
											<div class="form-group sr-only">
											 	<label class="col-md-3 control-label" for="id">id</label>
											  	<div class="col-md-9">
													<input type="text" id="uuid" name="uuid" placeholder="ID" class="form-control">
													<input type="text" id="tpId" name="tpId" class="form-control" value=""/>
											  	</div>
											</div>
											<div class="form-group">
												<label class="col-md-3 control-label no-padding-right" for="title">章节名称</label>
												<div class="col-md-9">
													<input id="title" class="form-control input-sm" type="text" placeholder="章节名称" name="title" data-bv-field="title">
												</div>
											</div>
										</fieldset>
										<div class="form-actions center">
											<button type="button" class="btn btn-sx btn-success" id="saveTitle">
												<i class="icon-save icon-on-left"></i>保存
			
											</button>
										</div>
									</form>
								</div>
							</div>
						</div>
						
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="docItemMaster.js"></script>  
<script src="${ctx}/static/ace/assets/js/fuelux/fuelux.tree.min.js"></script>
<script>

setting = {
		edit: {
			enable: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		data : {
			 key:{
				name:"title"
			},
			simpleData : {
				enable : true,
				idKey : "uuid",
				pIdKey : "parentId",
			} 
		},
		callback: {
			onClick:zTreeOnClick
		},
};
/* 显示章节信息 */
function zTreeOnClick(event, treeId, treeNode){
	
	if(!treeNode.children){
		//选择章节赋值
		$("#itemName").text(treeNode.title);
		/* 选择哪个章节 */
		$("#selectItembutton button:eq(0)").attr("key",treeNode.uuid);
		/* 删除章节赋id */
		$("#selectItembutton button:eq(1)").attr("key",treeNode.uuid);
		$("#buttons button:eq(1)").attr("key",treeNode.uuid);
		//修改赋值
		$("#itemUpdate").text("修改章节名字");
		$("#saveTitle").attr("key",treeNode.uuid);
		$("#title").val(treeNode.title);
	}	
}
</script>
<script>
/* var menuTree,options;

var treeObj;
var treeNodes;

var setting = {
	check: {
		enable: false
	},
	data : {
		simpleData : {
			enable : true,
			idKey : "uuid",
			pIdKey : "parentId"
		}
	},
	async : {
		enable : true,
		url : "${ctx}/pm/doc/item/getAllChildItemList.do",
		type:"post",
		autoParam : ["uuid"],
		otherParam:["tpId" , ""],
		dataFilter : filter
	},
	view : {
		selectedMulti : false
	},
	callback : {
		onAsyncSuccess : zTreeOnAsyncSuccess,
		onClick : zTreeOnClick
	}
};

function filter(treeId, parentNode, childNodes) {
	if (!childNodes)
		return null;
	for (var i = 0, l = childNodes.length; i < l; i++) {
		if(childNodes[i].title != null) {
			childNodes[i].name = childNodes[i].title.replace(/\.n/g, '.');
		}
	}
	return childNodes;
};

function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
	
	//让页面滚动条定位到顶部
	document.documentElement.scrollTop = 0; //IE
	document.body.scrollTop = 0; //Firefox
};
function zTreeOnClick(event, treeId, treeNode) {
	
	//得到章节的id
	$("#itemId").val(treeNode.uuid);
	 getItemById(treeNode.uuid);
     $('#menuEditForm').data('bootstrapValidator').resetForm();//重置表单验证
}; */

/* //菜单保存验证选项配置 
options = {
		message: '信息填写不完整',
		submitHandler: function(validator, form, submitButton) {
			Otod.ajax({
				url:"${ctx}/pm/doc/item/save.do",
				data: form.serialize(),
				contentType: "application/x-www-form-urlencoded;",
				successFn: function(data){
					var selectedNodes = treeObj.getSelectedNodes();
					if(selectedNodes.length>0){
						treeObj.reAsyncChildNodes(selectedNodes[0].getParentNode(), "refresh");
					}else{
						treeObj.reAsyncChildNodes(null, "refresh");
					}
					resetForm();
					Otod.Msg.info(data.info);
                 }
			 });
        },
        fields: {
        	menuName:{
        		message:'菜单名称不能为空',
        		validators:{
        			notEmpty: {
                        message: '菜单名称不能为空'
                    }
        		}
        	},
        	menuUri:{
        		message:'菜单Uri不能为空',
        		validators:{
        			notEmpty: {
                        message: '菜单Uri不能为空'
                    }
        		}
        	},
        	menuOrder:{
        		message:'菜单顺序为数字',
        		validators:{
        			digits:{
        				message:'菜单顺序为数字',
        			}
        		}
        	}
        }
}; */














//菜单查询事件：根据菜单ID查询菜单详细信息
/* function getItemById(id){
	Otod.ajax({
		url:"${ctx}/pm/doc/item/getItemById.do",
		data:id,
		successFn: function(data){
			 	for(var d in data){
					 if($("#"+d).is('select')){
						 $("#"+d).select2("val",data[d]); 
						 $("#parentId").select2("val", data.parentId);
					 }else{
					 	$("#"+d).val(data[d]);
					 };
			 	};
		}
	 });
}
 */







//获得jquery 对象
/* function getJqueryObj(obj){
	var jObj;
	if (obj.jquery) {
		jObj = obj;
	}else if(obj instanceof HTMLElement){
		jObj = $(obj);
	}else{
		jObj = $("#"+obj);
	}
	return jObj;
} */



/* $("#doctp-prjtype").on('click',".btn-doctpname",function(e){
	e.preventDefault();
	
	
	reloadTree($(this).attr("valuekey"));
}); */



//重新加载树
/* function reloadTree(tpId){
	$("#tpId").val(tpId);
	
	treeObj.setting.async.otherParam = ["tpId" , tpId];
	
	treeObj.reAsyncChildNodes(null, "refresh");
	
	
	getMenuList(tpId);
}
 */


/* 
$(document).ready(function() {
		$("#stepCfgMaster").hide();
		//新增 long
		if(prjId!=""&&prjType!=""&&stepId!=""){
			//设置项目类型为不可改动
			$("#prjType").val(prjType);
			//如果这种设置后台娶不到值
			$("#prjType").attr("disabled","true");
			$("#stepCfgMaster").show();
			$("#stepCfgMaster button").on("click",function(e){
			
				saveItem();
			})
		}
		
		
		//菜单节点选中事件 
		$('#menuTree').on('selected', function (evt, data) {
	        //加载表单信息
	        getMenuById(treeObj.getSelectedNodes()[0].uuid);
	        $('#menuEditForm').data('bootstrapValidator').resetForm();//重置表单验证
	    });
		
		
		//父节点关闭事件 
		$('#menuTree').on('closed', function (evt, data) {
			$('div.tree-folder-header.tree-selected').removeClass('tree-selected');
		});
		
		
		//验证
		$('#menuEditForm').bootstrapValidator(options);
		treeObj = $.fn.zTree.init($("#menuTree"), setting);
		
		getDocTpByPrjType();
		
		
		 
		
	}); */
</script>



</body>
</html>